#include "task_model.h"

#define _map(x,y)   (x%y)?1:0

static TASKSTATE TASKAPI(SysTaskInit)(struct TaskModel_t *vtask){

	printf("SysTaskInit_name : %s \n",vtask->name);
	vtask->Task_Delay = 0;
    vtask->state = SSTATE_RUNNING;

    return vtask->state;
}

static TASKSTATE TASKAPI(SysTaskRun)(struct TaskModel_t *vtask){

    TASK_INT index = 0;
    TASK_INT task_sun = TASK_SUM;
    struct TaskModel_t **task_list;
    struct TaskModel_t *task_cur;
    task_list = TASK_GET_LIST();

    while(task_sun--){
        index++;
        task_cur = task_list[index];
        if(task_cur != NULL){
            if (TASK_GET_Heartbeat()%task_cur->Task_Delay)
                task_cur->state = SSTATE_STOP;
            else
                task_cur->state = SSTATE_RUNNING;
        }else{
            break;
        }
    }
    vtask->state = SSTATE_RUNNING;

    return vtask->state;
}

static TASKSTATE TASKAPI(SysTaskWait)(struct TaskModel_t *vtask){

    
    vtask->state = SSTATE_RUNNING;

    return vtask->state;
}

struct TaskModel_t sys_task =
{
    "sys_task", &TASKAPI(SysTaskInit), &TASKAPI(SysTaskRun), NULL, SSTATE_RUNNING, 600,
};
